#include <iostream>
#include <string>
#include "test.pb.h"
using namespace fixbug;

int main() {
      // *****构造请求消息并序列化*****
    GetUserListRequest gulreq;
    gulreq.set_id_left(1);
    gulreq.set_id_right(10);

    std::string data;
    if(gulreq.SerializeToString(&data)) {
        std::cout << "data: " << data << std::endl;
    }

      // *****反序列化请求消息并构造响应消息*****
    GetUserListRequest gulreq2;
    gulreq2.ParseFromString(data);

      // 获取用户列表
    GetUserListResponse gulresp;
    gulresp.mutable_error()->set_err_code(0);
    gulresp.mutable_error()->set_err_msg("success");

    User *usr1 = gulresp.add_users();
    usr1->set_id(1);
    usr1->set_name("ljy");
    usr1->set_gender(User::MAN);

    User *usr2 = gulresp.add_users();
    usr2->set_id(2);
    usr2->set_name("zhangsan");
    usr2->set_gender(User::WOMAN);   
    
      // *****序列化响应消息*****
    if(gulresp.SerializeToString(&data)) {
        std::cout << "data: " << data << std::endl;
    }

    return 0;
}

int main1() {
    LoginRequest req;
    req.set_name("ljy");
    req.set_pwd("123456");

    std::string data;
    if(req.SerializeToString(&data)) {
        std::cout << data << std::endl;
    }

    std::cout << "=====================" << std::endl;

    LoginRequest req2;
    req2.ParseFromString(data);

    LoginResponse resp;
    resp.set_err_code(0);
    resp.set_err_msg(req2.name() + req2.pwd());
    resp.set_is_success(true);

    if(resp.SerializeToString(&data)) {
        std::cout << data << std::endl;
    }
    return 0;
}